/**
 * 添加或者修改页面
 */
var BasicPutgoodsInfoDlg = {
    data: {
        putgoodsCustomerId: "",
        putgoodsOperateName: "",
        putgoodsName: "",
        putgoodsContacts: "",
        putgoodsTel: "",
        putgoodsEmall: "",
        putgoodsWebsite: "",
        putgoodsRange: "",
        putgoodsIndustry: "",
        putgoodsProvinces: "",
        putgoodsCiywhere: "",
        putgoodsBank: "",
        putgoodsBankaccount: "",
        putgoodsCreditcode: "",
        putgoodsAddress: "",
        putgoodsNotes: "",
        version: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: "",
        xlbClientId:""
    }
};
var DictInfoDlg = {
    data: {
        dictId: "",
        name: ""
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/basicPutgoods/addItemhx", function (data) {
        	if (data.success) {
                Feng.success("添加成功！");
	        	var Index = parent.layer.getFrameIndex(window.name);
	            parent.layer.close(Index);
			} else {
                Feng.error("添加失败！"+data.message);
			}
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

	function getCaption (obj) {//截取指定字符后的字符串
	    var index = obj.lastIndexOf("|")+1
	    var res = obj.substring(index, obj.length)
	    return res
	}

    //父级字典时
    $('#name').click(function () {
        var formName = encodeURIComponent("parent.DictInfoDlg.data.name");
        var formId = encodeURIComponent("parent.DictInfoDlg.data.dictId");
        var treeUrl = encodeURIComponent("/hxBasicUnitCode/treeo?v1=" + $("#unitType").val());

        layer.open({
            type: 2,
            title: '所属分组',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#dictId").val(DictInfoDlg.data.dictId);
                $("#name").val(getCaption(DictInfoDlg.data.name));
            }
        });
    });

    form.on('select(careful1)',function(){
		$("#careful1Code").val($("#careful1").find("option:checked").attr("id"))
    });

    form.on('select(careful2)',function(){
		$("#careful2Code").val($("#careful2").find("option:checked").attr("id"))
    });
    form.on('select(careful3)',function(){
		$("#careful3Code").val($("#careful3").find("option:checked").attr("id"))
    });
    form.on('select(careful4)',function(){
		$("#careful4Code").val($("#careful4").find("option:checked").attr("id"))
    });

	form.verify({
        putgoodsNotes: function(value, item){
            if(value.length > 100){
                return '字数不得超过100';
            }
        }
    });

    //返回按钮
    $("#backupPage").click(function () {
        	var Index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(Index);
    });

});